# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: 线程锁练习.py
Author: kij
Create Date: 2021/3/19
-------------------------------------------------
"""
import time
from threading import Thread, Lock, currentThread

n = 100


def task():
	global n
	# 拿到锁
	mutex.acquire()
	temp = n
	time.sleep(0.1)
	n = temp-1
	# 放开锁
	mutex.release()


if __name__ == '__main__':
	mutex = Lock()
	t_l = []
	for item in range(20):
		t = Thread(target=task)
		t_l.append(t)
		t.start()

	for item in t_l:
		t.join()

	print(currentThread().getName(),n)
